package com.mcptt.config.body.info.mcptt;

import java.io.UnsupportedEncodingException;

public class McpttInfoBody_GCall extends McpttInfoBody{

	public static final int GroupCallType_prearranged = 1;
	private int callType = GroupCallType_prearranged;
	private String groupId = "";
	private String selfMcpttId = "";
	private String clientId = "";
	private boolean isEmergency = true;
	private String funcNum = null;

	public McpttInfoBody_GCall(int gCallType,String groupId,String selfMcpttId,String clientId,boolean isEmergency,String funcNum)
	{
		this.callType = gCallType;
		this.groupId = groupId;
		this.selfMcpttId = selfMcpttId;
		this.clientId = clientId;
		this.isEmergency = isEmergency;
		this.funcNum = funcNum;
	}
	
	public String toString()
	{
		StringBuffer strBuff = new StringBuffer();
		strBuff.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>").append("\r\n");
		strBuff.append("<mcpttinfo xmlns=\"urn:3gpp:ns:mcpttInfo:1.0\">").append("\r\n");
		strBuff.append("<mcptt-Params>").append("\r\n");
		//strBuff.append("<mcptt-request-uri type=\"Normal\">").append("\r\n");
		strBuff.append("<session-type>").append(getCallTypeDesc(callType)).append("</session-type>").append("\r\n");
		//strBuff.append("</ mcptt-request-uri>").append("\r\n");
		
		strBuff.append("<mcptt-request-uri type=\"Normal\">").append("\r\n");
		strBuff.append("<mcpttURI>").append(groupId).append("</mcpttURI>").append("\r\n");
		strBuff.append("</mcptt-request-uri>").append("\r\n");
		
		strBuff.append("<mcptt-client-id type=\"Normal\">").append("\r\n");
		strBuff.append("<mcpttURI>").append(clientId).append("</mcpttURI>").append("\r\n");
		strBuff.append("</mcptt-client-id>").append("\r\n");

		if(isEmergency) {
			strBuff.append("<emergency-ind type=\"Normal\">").append("\r\n");
			strBuff.append("<mcpttBoolean>").append(getBooleanDesc(isEmergency)).append("</mcpttBoolean>").append("\r\n");
			strBuff.append("</emergency-ind>").append("\r\n");
		}

		if(funcNum != null
				&& funcNum.length() > 0)
		{
			strBuff.append("<functional-alias-URI>").append("\r\n");
			strBuff.append("<mcpttURI>").append(funcNum).append("</mcpttURI>").append("\r\n");
			strBuff.append("</functional-alias-URI>").append("\r\n");
//			strBuff.append("<mcptt-calling-user-id>").append("\r\n");
//			strBuff.append("<mcpttURI>").append(selfMcpttId).append("</mcpttURI>").append("\r\n");
//			strBuff.append("</mcptt-calling-user-id>");
		}
		
		strBuff.append("</mcptt-Params>").append("\r\n");
		strBuff.append("</mcpttinfo>");
		
		try {
			return new String(strBuff.toString().getBytes(),"UTF-8");
		} catch (UnsupportedEncodingException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		return strBuff.toString();
	}
	

	
//	private String getClientInfo(final Context c)
//	{
//		TelephonyManager tm = (TelephonyManager)c.getSystemService(Context.TELEPHONY_SERVICE);
//		deviceId = tm.getDeviceId();
//
//
//		clientId = mPref.getString("UUID", "");
//		Log.d(TAG,"initAccount mPref clientId = "+clientId );
//		if(clientId == null
//				|| clientId.equals(""))
//		{
//			clientId = UUID.randomUUID().toString();
//			clientId = "urn:uuid:" + clientId;
//			SharedPreferences.Editor edit = mPref.edit();
//			edit.putString("UUID", clientId);
//			edit.commit();
//			Log.d(TAG,"initAccount save clientId = "+clientId );
//		}
//
//		if(deviceId == null
//				|| deviceId.equals("0"))
//		{
//			deviceId = clientId;
//		}
//	}
	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub

	}

}
